package CryptoPrim;

import Utils.TypeConvertionUtils;
import ArithmeticObjects.*;
import ArithUtils.*;

/**
 * A class which represents a Plaintext as Gq^w.
 * 
 * @author Itamar Carmel, amirzell
 */
public class Plaintext {
	
	// suppose u = (u1,...,uw)
	private Array<VerfGroup.VElement> elmArr; // u
	
	/**
	 * Constructor for Plaintext from an element array (u).
	 * 
	 * @param elmArr (u)
	 */
	public Plaintext(Array<VerfGroup.VElement> elmArr){
		this.elmArr = elmArr;
	}

	/**
	 * Constructor of PT which initiate the array 'u'.
	 */
	public Plaintext() {
		this.elmArr = new Array<VerfGroup.VElement>();
	}

	/**
	 * Getter for the i'th element.
	 * 
	 * @param i - index
	 * @return u[i]
	 */
	public VerfGroup.VElement get(int i){
		return this.elmArr.get(i);
	}
	
	/**
	 * Adds an element to u[length].
	 * 
	 * @param elm
	 */
	public void add(VerfGroup.VElement elm){
		this.elmArr.add(elm);
	}
	
	/**
	 * Getter for this PT width.
	 * 
	 * @return w (width of PT)
	 */
	public int getWidth(){
		return TypeConvertionUtils.bigNumberToInt(this.elmArr.getLength());
	}
	
	/**
	 * Generator of fixed PT by repeating element.
	 * 
	 * @param elm - the repeating element
	 * @param width - width of PT
	 * @return PT (fixed)
	 */
	public static Plaintext generateFixedPlaintext(VerfGroup.VElement elm, int width) {
		Plaintext ret = new Plaintext();
		for (int i=0; i<width; i++)
			ret.add(elm);
		return ret;
	}

	/**
	 * Getter for array of elements - u.
	 * 
	 * @return u
	 */
	public Array<VerfGroup.VElement> getArr() {
		return this.elmArr;
	}
}
